﻿// 实时钟表.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//

#include "pch.h"
#include <graphics.h>
#include <conio.h>
#include <math.h>

#define PI 3.14159



int main()
{
	initgraph(400, 400);
	setbkcolor(WHITE);
	cleardevice();

	int center_x = 200, center_y = 200;
	int secondlength = 80;
	int minutelength = 60;
	int hourlength = 40;
	int secondend_x, secondend_y;
	int minuteend_x,minuteend_y;
	int hourend_x, hourend_y;
	float secondangle = 0;
	float minuteangle = 0;
	float hourangle = 0;


	SYSTEMTIME ti;

	BeginBatchDraw();

	setlinestyle(PS_SOLID, 1);
	setlinecolor(BLACK);
	circle(200, 200, 100);




	while (1)
	{

		GetLocalTime(&ti);
		secondangle = ti.wSecond * 2 * PI / 60;
		minuteangle = ti.wMinute * 2 * PI / 60 + secondangle / 60;
		hourangle = ti.wHour * 2 * PI / 12 + minuteangle / 12;


		secondend_x = center_x + secondlength * sin(secondangle);
		secondend_y = center_y - secondlength * cos(secondangle);
		minuteend_x = center_x + minutelength * sin(minuteangle);
		minuteend_y = center_y - minutelength * cos(minuteangle);
		hourend_x = center_x + hourlength * sin(hourangle);
		hourend_y = center_y - hourlength * cos(hourangle);


		setlinestyle(PS_SOLID, 2);
		setcolor(BLACK);
		line(center_x, center_y, secondend_x, secondend_y);

		setlinestyle(PS_SOLID, 4);
		setcolor(RED);
		line(center_x, center_y, minuteend_x, minuteend_y);

		setlinestyle(PS_SOLID, 8);
		setcolor(BLUE);
		line(center_x, center_y, hourend_x, hourend_y);

		FlushBatchDraw();

		Sleep(50);

		setcolor(WHITE);
		line(center_x, center_y, secondend_x, secondend_y);
		line(center_x, center_y, minuteend_x, minuteend_y);
		line(center_x, center_y, hourend_x, hourend_y);
	}



	EndBatchDraw();
	getch();
	closegraph();
	return 0;
}

// 运行程序: Ctrl + F5 或调试 >“开始执行(不调试)”菜单
// 调试程序: F5 或调试 >“开始调试”菜单

// 入门提示: 
//   1. 使用解决方案资源管理器窗口添加/管理文件
//   2. 使用团队资源管理器窗口连接到源代码管理
//   3. 使用输出窗口查看生成输出和其他消息
//   4. 使用错误列表窗口查看错误
//   5. 转到“项目”>“添加新项”以创建新的代码文件，或转到“项目”>“添加现有项”以将现有代码文件添加到项目
//   6. 将来，若要再次打开此项目，请转到“文件”>“打开”>“项目”并选择 .sln 文件
